package com.newviews.tcmip.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.newviews.tcmip.pojo.po.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newviews.tcmip.web.vo.etcmherb.HerbIngrVo;
import com.newviews.tcmip.web.vo.etcmpx.PxDiseaseRespVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * <p>
 * 疾病基本信息 Mapper 接口
 * </p>
 *
 * @author lxc
 * @since 2024-03-01
 */
@Mapper
@CacheConfig(cacheNames = "EtcmStatistics")
public interface EtcmDiseaseMapper extends BaseMapper<EtcmDiseasePo> {

    @Cacheable(value = "diseaseCount")
    int indexDiseaseCount();

    List<EtcmHerbHerbPo> getHerbAndHerb(@Param(Constants.WRAPPER) QueryWrapper<EtcmHerbHerbPo> herbWrapper);

    List<EtcmIngrIngrPo> getIngrAndIngr(@Param(Constants.WRAPPER) QueryWrapper<EtcmIngrIngrPo> ingrWrapper);

    List<EtcmHerbDiseasePo> getHerbAndDisease(@Param(Constants.WRAPPER) QueryWrapper<EtcmHerbDiseasePo> herbDiseaseWrapper);

    List<EtcmIngrDiseasePo> getIngrAndDisease(@Param(Constants.WRAPPER) QueryWrapper<EtcmIngrDiseasePo> ingrDiseaseWrapper);

    List<HerbIngrVo> getHerbAndIngr(@Param(Constants.WRAPPER) QueryWrapper<HerbIngrVo> herbIngrWrapper);

    List<PxDiseaseRespVo> getPxAndDisease(@Param(Constants.WRAPPER) QueryWrapper<PxDiseaseRespVo> herbDiseaseWrapper,@Param("targetName") List<String> targetName);
    //@Select("SELECT DISTINCT ingr_id FROM etcm_herb_ingr WHERE herb_id in (#{targetName})")
    List<String> getIngrCodeByHerbHerb( @Param("targetName") List<String> targetName);
    @Select("\tSELECT DISTINCT t2.herb_id\n" +
            "\t(SELECT DISTINCT herb_id FROM etcm_herb_disease WHERE disease_id = #{sourceName}) t1 \n" +
            "\tLEFT JOIN etcm_herb_ingr t2 ON t1.herb_id = t2.herb_id \n" +
            "\tWHERE t2.px_code in (#{targetName})")


    List<String> getHerbCodeByPxDiseaseList(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
    @Select("\t\tSELECT DISTINCT t2.ingr_id\n" +
            "\t(SELECT DISTINCT ingr_id FROM etcm_ingr_disease WHERE disease_id = #{sourceName}) t1 \n" +
            "\tLEFT JOIN etcm_herb_ingr t2 ON t1.ingr_id = t2.ingr_id \n" +
            "\tWHERE t2.px_code in (#{targetName})")


    List<String> getIngrCodeByPxDiseaseList(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
    @Select("\tSELECT DISTINCT t2.disease_id\n" +
            "\t(SELECT DISTINCT herb_id FROM etcm_herb_ingr WHERE px_code in(#{targetName})) t1\n" +
            "\tLEFT JOIN etcm_herb_disease t2 ON t1. herb_id = t2.herb_id \n" +
            "\tWHERE t2.disease_id = #{sourceName}")
    List<String> getDiseaseCodeByPxDiseaseList(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
    @Select("SELECT DISTINCT herb_id FROM etcm_herb_disease WHERE disease_id = #{sourceName} and  herb_id in (#{targetName})")
    List<String> getHerbCodeByHerbDiseaseList(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
    @Select("\t\tSELECT DISTINCT t2.disease_id\n" +
            "\t(SELECT DISTINCT ingr_id FROM etcm_herb_ingr WHERE herb_id in(#{targetName})) t1\n" +
            "\tLEFT JOIN etcm_ingr_disease t2 ON t1.ingr_id = t2.ingr_id \n" +
            "\tWHERE t2.disease_id = #{sourceName}")
    List<String> getIngrCodeByHerbDiseaseList(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
    @Select("SELECT DISTINCT disease_id FROM etcm_herb_disease WHERE disease_id = #{sourceName} and  herb_id in (#{targetName})")
    List<String> getDiseaseCodeByHerbDiseaseList(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
    @Select("SELECT DISTINCT ingr_id FROM etcm_ingr_disease WHERE disease_id = #{sourceName} and  ingr_id in (#{targetName})")
    List<String> getIngrCodeByIngrDisease(@Param("sourceName") String sourceName, @Param("targetName") List<String> targetName);
}
